<!--党员组织关系转入获得奖项表单-->
<template>
  <div class="form">
    <yd-cell-group>
      <yd-cell-item>
        <span slot="left" class="label required">获奖时间</span>
        <xf-date-picker
          :valid="[{required: true, msg: '请选择获奖时间'}]"
          v-model="form.rewardDate"
          ref="rewardDate"
          placeholder="请选择获奖时间"
          :endDate="new Date()"
          slot="right"></xf-date-picker>
      </yd-cell-item>
      <yd-cell-item>
        <span slot="left" class="label required">奖项名称</span>
        <xf-picker
          slot="right"
          :valid="[{required: true, msg: '请选择奖项名称'}]"
          v-model="form.rewardCode"
          :text.sync="form.rewardName"
          ref="rewardCode"
          :list="rewards"
          placeholder="请选择奖项名称"></xf-picker>
      </yd-cell-item>
      <yd-cell-item>
        <span slot="left" class="label required">奖励批准单位</span>
        <xf-input
          :valid="[{required: true, msg: '请填写奖励批准单位'}]"
          v-model="form.rewardCompanyName"
          ref="rewardCompanyName"
          slot="right"
          placeholder="请填写奖励批准单位"></xf-input>
      </yd-cell-item>
    </yd-cell-group>
    <div class="right-bottom">
      <mt-button type="default" size="small" @click="cancel">取消</mt-button>
      <mt-button type="primary" size="small" @click="onSubmit">保存</mt-button>
    </div>
  </div>
</template>
<script>
  import XfDatePicker from '../../../components/xf-date-picker/xf-date-picker.vue'
  import XfInput from '../../../components/xf-input/xf-input.vue'
  import {dics, getDics} from '../../../common/js/dictionaries'
  import XfPicker from '../../../components/xf-picker/xf-picker'
  import {echo, validate} from '../../../common/js/util'

  export default {
    props: {
      detail: {type: null, default: () => { return {} }}
    },
    components: {
      XfPicker,
      XfInput,
      XfDatePicker},
    name: 'roll-in-award-form',
    data() {
      return {
        form: {
          id: '',
          rewardDate: '', // 奖励时间
          rewardCode: '', // 奖励名称代码
          rewardCompanyName: '', // 奖励批准单位名称
          rewardName: '' // 奖励名称
        },
        rewards: []
      }
    },
    methods: {
      cancel() {
        this.$emit('cancel')
      },
      onSubmit() {
        validate.bind(this)(this.form).then(() => {
          const form = Object.assign({}, this.form)
          form.personId = this.$route.query.id
          form.type = 1
          this.$post('/admin/person/sapi/party/reward/punishment/update', form).then(res => {
            this.$emit('save')
          })
        })
      },
      getDics() {
        getDics(dics.reward).then(res => {
          this.rewards = res[0]
        })
      }
    },
    created() {
      this.getDics()
      echo(this.form, this.detail)
    }
  }
</script>
<style scoped lang="scss">
  @import "../../../common/style/variable";
  .img-box{
    width: 100%;
    padding: .2rem .2rem;
    display: flex;
    .upload-img{
      width: 2rem;
    }
  }
</style>
